<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>项目大事记</title>
    <!--公用样式-->
    <link rel="stylesheet" type="text/css" href="${re.contextPath}/plugin/common/css/comment.css"/>
    <!--页面样式-->
    <link rel="stylesheet" type="text/css" href="${re.contextPath}/plugin/common/css/style.css"/>
    <!--Layui-->
    <link rel="stylesheet" href="${re.contextPath}/plugin/layui/css/layui.css" media="all"/>
    <!--extended-->
    <link rel="stylesheet" type="text/css" href="${re.contextPath}/plugin/common/css/extended.css"/>
    <!--公用样式JS-->
    <script type="text/javascript" src="${re.contextPath}/plugin/jquery/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="${re.contextPath}/plugin/common/js/comment.js"></script>
    <script type="text/javascript" src="${re.contextPath}/plugin/layui/layui.js" charset="utf-8"></script>
</head>
<body>

<script type="text/html" id="toolBar">


    <a class="layui-btn layui-btn-xs  layui-btn-normal" lay-event="save" style="margin-left: 0px;width: 60px;">保存</a>
    <a class="layui-btn layui-btn-xs  layui-btn-normal" lay-event="updateCancle" style="margin-left: 0px;width: 60px;">取消</a>
</script>
<div class="project whitebg">
    <div class="right clearfix">
        <button type="button" id="export" class="layui-btn layui-btn-normal"> 导出</button>
    </div>
    <div>
        <input type="hidden" id="projectId" value="${projectId}">
        <input type="hidden" id="projectName" value="${project.projectName}">
        <table id="tableList" style="height: 400px;" class="layui-hide" lay-filter="tableList"></table>
    </div>
    <div style="display: none">
        <table id="table">
        </table>
    </div>
</div>
<script type="text/javascript" src="${re.contextPath}/plugin/tools/tool.js"></script>
<script type="text/javascript">
    var layer;
    var form = layui.form;
    var table = null;
    var tableIns = null;
    var laydate;
    //注意进度条依赖 element 模块，否则无法进行正常渲染和功能性操作
    var element = "";
    layui.use('element', function () {
        element = layui.element;
    });

    layui.use(['form', 'laydate', 'table','layer'], function () {
        table = layui.table;
        element = element;
        laydate = layui.laydate;
        var isShow= '${show}';
        var ishide=false;
        var lwidth="20%";
        if(isShow!="1"){
            ishide=true;
             lwidth="50%";
        }

        //方法级渲染
        tableIns = table.render({
            id: 'tableList',
            elem: '#tableList',
            title: '项目大事记',
            url: '/supervisor/projectManager/queryBigEvent?projectId=' + '${projectId}',
            cols: [[
                {
                    title: '序号', width: '10%', align: 'center',templet: function (res) {
                        return res.LAY_INDEX;
                    }
                },
                {field: 'proEventId', title: 'id', width: '20%', align: 'center',hide:true},
                {field: 'stageName', title: '阶段名称', width: '20%', align: 'center'},
                {field: 'milePostName', title: '里程名称', width: '20%',align: 'center'},
                {field: 'operDate', title: '时间',width:lwidth,align: 'center',edit: 'text',event: 'editGetDate'},
                {field: 'remark', title: '操作', width:'30%', toolbar: "#toolBar",hide:ishide,align: 'center'}

            ]],
            height: 'full-110',
            page: true,
            done: function (res, currentCount) {
                //***重点***：table渲染完成后渲染element进度条
                $(".layui-table-page select").css("width","80px");
                element.render()
            }
        });
        var  projectName="${project.projectName}";
        table.render({
            elem: '#table',
            id: 'exportTable',
            title: projectName+'_项目大事记',
            cols: [[ //表头
                {
                    field: 'ordernum',
                    title: '序号',
                }, {
                    field: 'stageName',
                    title: '阶段名称',
                }, {
                    field: 'milePostName',
                    title: '里程名称',
                }, {
                    field: 'operDate',
                    title: '时间',
                    width:'80%'
                }

            ]]
        });
        //监听工具条
        var datastr="";
        table.on('tool(tableList)', function (obj) {
            var  data = obj.data;
            var proEventId=data.proEventId;
            var that=$(this);
            if (obj.event === "editGetDate") {
                var field = $(this).data('field');
                laydate.render({
                    elem: this.firstChild,
                    show: true,
                    closeStop: this,
                    done: function (value, res) {
                        obj.data[field] = value;
                        var tabledata = layui.table.cache.tableList;
                        var _aln = tabledata.length;
                        for(var i=0;i<_aln;i++){
                            if(tabledata[i].proEventId=proEventId){
                               tabledata[i].operDate=value;
                            }
                        }
                        obj.update(res);
                    }
                });
            }else  if(obj.event === "save"){
                /*保存*/
                var tabledata = layui.table.cache.tableList;
                var _aln = tabledata.length;
                var operDate="";
                for(var i=0;i<_aln;i++){
                    if(tabledata[i].proEventId==proEventId){
                        operDate=tabledata[i].operDate;
                    }
                }
                layer.confirm('确定修改吗？', function (index) {
                    layerAjax('/supervisor/projectManager/updateBigEvent', {proEventId: data.proEventId,operDate:operDate}, null, function (d) {
                        if (d.flag) {

                            layer.msg(d.msg, {icon: 1});
                            tableIns.reload();
                        } else {
                            layer.msg(d.msg, {icon: 2});
                        }
                    });
                });

            }else  if(obj.event === "updateCancle"){

                layer.confirm('确定取消吗？', function (index) {
                    layerAjax('/supervisor/projectManager/updateCancleBigEvent', {proEventId: data.proEventId}, null, function (d) {
                        if (d.flag) {
                            layer.msg(d.msg, {icon: 1});
                            tableIns.reload();
                        } else {
                            layer.msg(d.msg, {icon: 2});
                        }
                    });
                });

            }
        });



    });

    //导出事件
    $('#export').on('click', function () {
        var projectId =  '${projectId}'
        window.open('/supervisor/projectManager/getBigEventData?projectId=' + projectId)
        //使用ajax请求获取所有数据
        /*layerAjaxGet('/supervisor/projectManager/getBigEventData', json, '', function (d) {
            if (d.flag) {
                var str = "";
                var jsonarry = new Array();
                var k = 0;
                var count = 0;
                for (var y = 0; y < d.data.length; y++) {
                   var  json=d.data[y];
                    k=k+1;
                    json.ordernum=k;
                    jsonarry.push(json);
                }
                table.exportFile('exportTable',jsonarry, 'xls');
            } else {
                layer.msg(d.msg, {icon: 2});
            }
        });*/
    });

</script>

</body>

</html>
